//
//  AspectSecondViewController.m
//  runtimeDemo
//
//  Created by admin on 2018/2/27.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "AspectSecondViewController.h"

@interface AspectSecondViewController ()

@property (nonatomic, assign) int count;

@end

@implementation AspectSecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

// 用GCD实现倒计时
- (void)countDownTime {
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
    dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC, 0 * NSEC_PER_SEC);
    dispatch_source_set_event_handler(timer, ^{
        dispatch_async(dispatch_get_main_queue(), ^{
            if (_count == 0) {
                dispatch_cancel(timer);
            } else {
                _count--;
            }
        });
    });
    dispatch_resume(timer);
}


@end
